package com.crm.controller;

import com.crm.api.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;

@RestController
public class AccountInfoController {

    @Autowired
    private UserService userService;


    @RequestMapping(value = "/account",method = RequestMethod.GET)
    public Object getAccount(@RequestParam(value = "account")String account){
        Object obj = userService.getUserInfo();
        if(Proxy.isProxyClass(userService.getClass())){
            Class<?> proxyClass = Proxy.getProxyClass(UserService.class.getClassLoader(), UserService.class);
            System.out.println(proxyClass.getName());
        }
        System.out.println(userService.getClass().getName());
        Map<String,Object> response = new HashMap<>();
        response.put("userInfo",obj);
        response.put("account",account);
        return response;
    }

    @RequestMapping(value = "/account/info",method = RequestMethod.GET)
    public Object getAccountInfoById(@RequestParam(value = "id")Long id){
        Object obj = userService.getUserInfoById(id);
        Map<String,Object> response = new HashMap<>();
        response.put("info",obj);
        response.put("accountInof","/account/Info/"+id);
        return response;
    }
}
